package com.cskaoyan.config;

import com.cskaoyan.interceptor.CountTimeAdvice;
import com.cskaoyan.service.UserService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author stone
 * @date 2022/11/11 17:25
 */
@Configuration
@ComponentScan("com.cskaoyan")
public class ApplicationConfiguration {

    @Bean
    public ProxyFactoryBean userServiceProxy(UserService userService) {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        // 委托类对象
        proxyFactoryBean.setTarget(userService);
        // 设置拦截器（通知组件）的名称
        proxyFactoryBean.setInterceptorNames("countTimeAdvice");

        return proxyFactoryBean;
    }
}
